package cn.tedu.file;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/*本类用于测试字符输出流*/
public class TestOut2 {
    public static void main(String[] args) {
        //method1();//用于测试普通字符输出流
        method2();//用于测试字符输出流
    }

    private static void method2() {
        BufferedWriter out=null;

        try{
            //会覆盖输出的创建高效输出流对象
           // out=new BufferedWriter(new FileWriter(new File("F:\\ready\\1.txt")));
           // out=new BufferedWriter(new FileWriter("F:\\ready\\1.txt"));
            //会追加输出的创建高效输出流对象
            out=new BufferedWriter(new FileWriter(new File("F:\\ready\\1.txt"),true));
            //                                        out=new BufferedWriter(new FileWriter("F:\\ready\\1.txt",true));
            out.write(98);
            out.write(98);
            out.write(98);
            out.write(98);
            out.write(98);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    private static void method1() {
        //1,定义局部变量
        FileWriter out=null;
        //2,完成异常捕获处理结构
        try {
            //3.1,创建覆盖输出的字符流对象
           // out=new FileWriter(new File("F:\\ready\\1.txt"));
            //out=new FileWriter("F:\\ready\\1.txt");
            //3.2,创建追加输出的字符流对象
            out=new FileWriter(new File("F:\\ready\\1.txt"),true);
            out=new FileWriter("F:\\ready\\1.txt",true);
            //4，使用流对象输出数据
            out.write(97);
            out.write(98);
            out.write(99);
            out.write(100);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}
